//
//  AXFMineController.m
//  爱鲜蜂-我的
//
//  Created by Joker on 2016/11/19.
//  Copyright © 2016年 new moon. All rights reserved.
//

#import "AXFMineController.h"
#import "AXFMineLayout.h"
#import "Masonry.h"
#import "AXFMineHeadView.h"
#import "UIColor+CZAddition.h"
#import "AXFSecondCell.h"
#import "AXFCouponVC.h"
#import "AXFSettingController.h"
#import "AXFBalanceVC.h"
#import "AXFCreditsMallVC.h"
#import "AXFThirdCell.h"
#import "AXFAddressMainController.h"
#import "AXFMessageMainVC.h"
#import "AXFCreditsVC.h"
#import "AXFFirstCell.h"
#import "AXFMineOrderViewController.h"
#import "AXFRefundAndServiceViewController.h"
#import "AXFGoodsCollectViewController.h"
#import "AXFShopCollectViewController.h"
#import "AXFServiceFeedbackController.h"
#import "AXFFouthCell.h"
#import "AXFJoinController.h"

static NSString * FirstCellID = @"FirstCellID";
static NSString * SecondCellID = @"SecondCellID";
static NSString * ThirdCellID = @"ThirdCellID";
static NSString * FouthCellID = @"FouthCellID";

@interface AXFMineController ()
<
UICollectionViewDelegate,
UICollectionViewDataSource,
AXFSecondCellDelegate,
AXFMineHeadViewDelegate,
AXFThirdCellDelegate,
AXFFirstCellDelegate
>

@property (nonatomic,weak) UICollectionView * collectionView;

@property (nonatomic,weak) UIView * headView;

@end

@implementation AXFMineController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBarController.tabBar.translucent = NO;
    
}

#pragma mark 1.搭建界面
- (void)setupUI{
    
    //添加两个主要的view
    AXFMineHeadView * headV = [[AXFMineHeadView alloc]init];
    self.headView = headV;
    [self.view addSubview:headV];
    
    //设置代理
    headV.delegate = self;
    
    
    UICollectionView * CV = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:[[AXFMineLayout alloc]init]];
    CV.backgroundColor = [UIColor cz_colorWithHex:0xefefef];
    self.collectionView = CV;
    [self.view addSubview:CV];
    
    CV.dataSource = self;
    CV.delegate = self;
    
    //注册
    [self.collectionView registerNib:[UINib nibWithNibName:@"AXFFirstCell" bundle:nil] forCellWithReuseIdentifier:FirstCellID];
    [self.collectionView registerNib:[UINib nibWithNibName:@"AXFSecondCell" bundle:nil] forCellWithReuseIdentifier:SecondCellID];
    [self.collectionView registerNib:[UINib nibWithNibName:@"AXFThirdCell" bundle:nil] forCellWithReuseIdentifier:ThirdCellID];
    [self.collectionView registerNib:[UINib nibWithNibName:@"AXFFouthCell" bundle:nil] forCellWithReuseIdentifier:FouthCellID];
//    [self.collectionView registerClass:[AXFFouthCell class] forCellWithReuseIdentifier:FouthCellID];
    
    //设置约束
    [headV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.mas_offset(175);
    }];
    
    [CV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headV.mas_bottom);
        make.left.bottom.right.equalTo(self.view);
    }];
 
}

#pragma mark 2.collectionView的数据源方法


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 4;

}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * indentify = FirstCellID;
    
    if (indexPath.row == 1) {
        
        indentify = SecondCellID;
        AXFSecondCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:indentify forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
        
    }else if(indexPath.row == 2){
        
        indentify = ThirdCellID;
        AXFThirdCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:indentify forIndexPath:indexPath];
        cell.delegate = self;
        return cell;
    }else if(indexPath.row == 3){
        
        indentify = FouthCellID;
        UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:indentify forIndexPath:indexPath];
        
        return cell;
    }
    
    AXFFirstCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:indentify forIndexPath:indexPath];
    
    cell.delegate = self;
    
        return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        return CGSizeMake(self.view.frame.size.width, 116);
    }
    
    if (indexPath.row == 1) {
        return CGSizeMake(self.view.frame.size.width, 112);
    }
    
    if (indexPath.row == 2) {
        return CGSizeMake(self.view.frame.size.width, 200);
    }
    
    return CGSizeMake(self.view.frame.size.width, 120);


    
}

#pragma mark 3.代理方法实现跳转

//headView设置按钮跳转
- (void)MineHeadView:(AXFMineHeadView *)headView WithSettingBtn:(UIButton *)Btn{

    AXFSettingController * settingVC = [[AXFSettingController alloc]init];
    
    [self.navigationController pushViewController:settingVC animated:YES];

}

//headView商品收藏
- (void)MineHeadView:(AXFMineHeadView *)headView WithGoodBtn:(UIButton *)Btn{

    AXFGoodsCollectViewController * goodsCollectVC = [[AXFGoodsCollectViewController alloc]init];
    
    [self.navigationController pushViewController:goodsCollectVC animated:YES];

}

//headView店铺收藏
- (void)MineHeadView:(AXFMineHeadView *)headView WithShopBtn:(UIButton *)Btn{

    AXFShopCollectViewController * shopCollectVC = [[AXFShopCollectViewController alloc]init];
    
    [self.navigationController pushViewController:shopCollectVC animated:YES];

}

//我的钱包优惠券跳转
- (void)AXFSecondCell:(AXFSecondCell *)secondCell button2:(UIButton *)btn{
    
    AXFCouponVC * cvc = [[AXFCouponVC alloc]init];
    
    [self.navigationController pushViewController:cvc animated:YES];
    
}

//我的钱包余额跳转
- (void)AXFSecondCell:(AXFSecondCell *)secondCell button1:(UIButton *)btn{

    AXFBalanceVC * balanceVC = [[AXFBalanceVC alloc]init];
    
    [self.navigationController pushViewController:balanceVC animated:YES];

}

//我的钱包积分跳转
- (void)AXFSecondCell:(AXFSecondCell *)secondCell button3:(UIButton *)btn{
    
    AXFCreditsVC * creditsVC = [[AXFCreditsVC alloc]init];
    
    [self.navigationController pushViewController:creditsVC animated:YES];
    
}

//thirdCell收货地址跳转
- (void)AXFThirdCell:(AXFThirdCell *)thirdCell withBtn2:(UIButton *)btn{
    
    AXFAddressMainController * addressVC = [[AXFAddressMainController alloc]init];
    
    [self.navigationController pushViewController:addressVC animated:YES];

}

//thirdCell我的消息跳转
- (void)AXFThirdCell:(AXFThirdCell *)thirdCell withBtn3:(UIButton *)btn{

    AXFMessageMainVC * messageVC = [[AXFMessageMainVC alloc]init];

    
    [self.navigationController pushViewController:messageVC animated:YES];
    
}

//thirdCell积分商城跳转
- (void)AXFThirdCell:(AXFThirdCell *)thirdCell withBtn1:(UIButton *)btn{

    AXFCreditsMallVC * creditsVC = [[AXFCreditsMallVC alloc]init];
    
    [self.navigationController pushViewController:creditsVC animated:YES];
    
}

//thirdCell客服/反馈跳转
- (void)AXFThirdCell:(AXFThirdCell *)thirdCell withBtn4:(UIButton *)btn{

    AXFServiceFeedbackController * serviceFeedbackVC = [[AXFServiceFeedbackController alloc]init];
    
    [self.navigationController pushViewController:serviceFeedbackVC animated:YES];
}

//thirdCell加盟合作跳转
- (void)AXFThirdCell:(AXFThirdCell *)thirdCell withBtn5:(UIButton *)btn{

    AXFJoinController * joinVC = [[AXFJoinController alloc]init];
    
    [self.navigationController pushViewController:joinVC animated:YES];
}

//订单页面我的订单跳转
- (void)AXFFirstCell:(AXFFirstCell *)firstCell withOrderBtn:(UIButton *)btn{

    AXFMineOrderViewController * orderVC = [[AXFMineOrderViewController alloc]init];
    orderVC.mineOrderButtonTag = btn.tag;
    [self.navigationController pushViewController:orderVC animated:YES];

}

//订单页面其他按钮跳转
- (void)AXFFirstCell:(AXFFirstCell *)firstCell withOtherBtns:(UIButton *)btn{
    
    AXFMineOrderViewController * orderVC = [[AXFMineOrderViewController alloc]init];
    orderVC.mineOrderButtonTag = btn.tag;
    [self.navigationController pushViewController:orderVC animated:YES];

}

//订单页面退款售后按钮跳转
- (void)AXFFirstCell:(AXFFirstCell *)firstCell withRefundBtns:(UIButton *)btn{

    AXFRefundAndServiceViewController * RefundAndServiceVC = [[AXFRefundAndServiceViewController alloc]init];
    
    [self.navigationController pushViewController:RefundAndServiceVC animated:YES];

}





- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
